package com.example.testdemo.designModel;

/**
 *   双重判定 加  volatile  防止指令重排解决懒汉式--线程不安全问题
 */
public class SinglonFor {

        public  static  volatile  SinglonFor  instance;

        public  SinglonFor(){
            System.out.println("=======构造方法");
        }

        public  static  SinglonFor getInstance(){
            if(instance==null){
                synchronized (SinglonFor.class){
                    if(instance==null){
                        instance=new SinglonFor();
                    }
                }
            }
            return  instance;
        }

}

class  TestDemoSinglo{
    public static void main(String[] args) {
        SinglonFor s1=SinglonFor.getInstance();
        SinglonFor s2=SinglonFor.getInstance();

        System.out.println(s1==s2);
    }
}
